<template>
  <div class="tab-bar-item" :style="activeStyle" @click="itemClick">
    <div class="content"><slot name="content"></slot></div>
    <h3 class="title"><slot name="title"></slot></h3>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  methods: {
    itemClick() {
      this.$router.replace(this.path);
    },
  },
  props: {
    color: {
      default: "#333",
    },
    path: {},
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) === 0;
    },
    activeStyle() {
      return this.isActive === true ? { color: this.color } : {};
    },
  },
};
</script>

<style scoped>
.tab-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-content: center;
}
.title {
  text-align: center;
  font-size: 12px;
}
.content {
  text-align: center;
  margin-top: 4px;
  font-size: 24px;
}
.content img {
  width: 24px;
  height: 24px;
}
</style>
